package com.fj.netty.chat.serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author fj
 * @date 2024/1/16 16:23
 */
public class SerializeConfig {

    public static final String SERIALIZE_ALGORITHM = "serialize.algorithm";
    private static Properties properties = new Properties();

    public static final String APPLICATION_PROPERTIES = "/application.properties";

    static {
        InputStream resourceAsStream = SerializeConfig.class.getResourceAsStream(APPLICATION_PROPERTIES);
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Serializer.Algorithm getSerializer(){
        String algorithm = properties.getProperty(SERIALIZE_ALGORITHM);
        if (algorithm == null || algorithm.isEmpty()){
            return Serializer.Algorithm.JAVA;
        }
        return Serializer.Algorithm.valueOf(algorithm);
    }
}
